package com.hpq.user.controller;

import com.hpq.common.domain.vo.request.CursorPageBaseReq;
import com.hpq.common.domain.vo.request.PageBaseReq;
import com.hpq.common.domain.vo.response.ApiResult;
import com.hpq.common.domain.vo.response.CursorPageBaseResp;
import com.hpq.common.domain.vo.response.PageBaseResp;
import com.hpq.common.utils.RequestHolder;
import com.hpq.user.domain.vo.request.friend.FriendApplyReq;
import com.hpq.user.domain.vo.request.friend.FriendCheckReq;
import com.hpq.user.domain.vo.request.friend.FriendDeleteReq;
import com.hpq.user.domain.vo.response.friend.FriendApplyResp;
import com.hpq.user.domain.vo.response.friend.FriendCheckResp;
import com.hpq.user.domain.vo.response.friend.FriendResp;
import com.hpq.user.service.FriendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
/**
 * 好友相关接口
 */
@RestController
@RequestMapping("/capi/user/friend")
@Api(tags ="好友相关接口")
@Slf4j
public class FriendController {
    @Autowired
    private FriendService friendService;


    @PostMapping("/apply")
    @ApiOperation("申请好友")
    public ApiResult<Void> apply(@Valid @RequestBody FriendApplyReq req ){
        Long uid = RequestHolder.get().getUid();
        friendService.apply(uid,req);
        return ApiResult.success();
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除好友")
    public ApiResult<String> delete(@Valid @RequestBody FriendDeleteReq req){
        Long uid = RequestHolder.get().getUid();
        friendService.deleteFriend(uid,req);
        return ApiResult.success("删除成功");
    }
    /**
     * 检查是否为好友
     * @param req
     * @return
     */
    @GetMapping("/check")
    @ApiOperation("检查是否为好友")
    public ApiResult<FriendCheckResp> checkFriend(@Valid FriendCheckReq req) {

        Long uid = RequestHolder.get().getUid();
        return ApiResult.success(friendService.check(uid, req));

    }
    /**
     *  分页查询好友列表
     * @param req
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("分页查询联系人列表")
    public ApiResult<CursorPageBaseResp<FriendResp>> getFriendListByCursor(@Valid CursorPageBaseReq req){
        Long uid = RequestHolder.get().getUid();
        return ApiResult.success(friendService.getFriendList(uid,req));
    }
    /**
     * 好友申请列表
     */
    @GetMapping("/apply/page")
    @ApiOperation("获取好友申请列表")
    public ApiResult<PageBaseResp<FriendApplyResp>> getFriendApplyByPage(@Valid PageBaseReq req){
        Long uid = RequestHolder.get().getUid();
        return ApiResult.success(friendService.getFriendApplyByPage(uid,req));
    }
}
